package cn.com.KnowNews.servlet;

import cn.com.KnowNews.entity.News;
import cn.com.KnowNews.service.INewsService;
import cn.com.KnowNews.service.imlp.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "DelNewsServlet",urlPatterns = "/DelNews")
public class DelNewsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();
        int id = Integer.parseInt(request.getParameter("id"));
        INewsService newsService = new NewsServiceImpl();
        try {
            newsService.delNew(id);
            request.getSession().setAttribute("news",newsService.showAllNews());
            response.sendRedirect("ShowAllCategory");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
